package com.tamplus.cs.bean;

import java.util.Locale;
import java.util.TimeZone;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import com.tamplus.cs.helper.MessageHelper;


public abstract class BaseBean {
	protected final String FWD_SUCCESS		= "success";
	protected final String FWD_CANCEL		= "cancel";
	protected final String FWD_PREVIEW		= "preview";
	protected final String FWD_BACK			= "back";
	protected final String FWD_CREATE		= "create";
	protected final String FWD_CLOSE		= "close";
	
	private int page = 1;
	private Locale locale;
	private TimeZone timeZone;
	
	public void setErrorMessage(String summary) {
		FacesContext context = FacesContext.getCurrentInstance();
		context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, summary, null));
	}

	public void setInfoMessage(String summary) {
		FacesContext context = FacesContext.getCurrentInstance();
		context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, summary, null));
	}
	
	public void displayInfoMessage(String key, Object[] parameters) {
		FacesContext context = FacesContext.getCurrentInstance();
		String info = MessageHelper.getLocaleString(context.getApplication().getMessageBundle(), key, parameters, Locale.US);
		setInfoMessage(info);
	}
	
	public void displayErrorMessage(String key, Object[] parameters) {
		FacesContext context = FacesContext.getCurrentInstance();
		String error = MessageHelper.getLocaleString(context.getApplication().getMessageBundle(), key, parameters, Locale.US);
		setErrorMessage(error);
	}

	public Locale getLocale() {
		Locale locale = Locale.US;
		Locale.setDefault(Locale.US);
		return locale;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public TimeZone getTimeZone() {
		timeZone = TimeZone.getTimeZone("Asia/Bangkok");
		return timeZone;
	}

	public void setTimeZone(TimeZone timeZone) {
		this.timeZone = timeZone;
	}

	public void setLocale(Locale locale) {
		this.locale = locale;
	}
	
}
